#ifndef THREAD_H
#define THREAD_H

#include <visibility.h>
#include <stdint.h>
#include <nuttx/pthread.h>
#include "NoCopy.h"

class Runnable;

class __EXPORT Thread : NoCopy {
public:
	Thread(const char *name, int stackSize, int priority, Runnable *runnable);
	~Thread();
	void join();
	static void sleep(uint32_t msec);
	static void yield();
	static uint32_t getTime();
		
private:
	Thread();	// disabled
	static void *execute(void *p);

	Runnable *runnable_;
	pthread_t pthread_;
};


/**
 * Implements periodic functional.
 */
class __EXPORT Period : NoCopy {
public:
	explicit Period(uint32_t period);
	void set(uint32_t period);
	void wait();	
	
private:
	Period();	// disabled
	uint32_t lastWakeTime_;
	uint32_t period_;
};


#endif
